﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControls_EmpresasSearchList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PopulateControls();
    }

    private void PopulateControls()
    {
        string pageEmp = Request.QueryString["PageEmp"];
        string page = Request.QueryString["Page"];
        if (page == null) page = "1";
        if (pageEmp == null) pageEmp = "1";
        // Retrieve Search string from query string
        string searchString = Request.QueryString["Search"];
        // How many pages of products?
        int howManyPages = 1;
        // pager links format
        string firstPageUrl = "";
        string pagerFormat = "";

        // If performing a search
        if (searchString != null)
        {
            // Retrieve AllWords from query string
            string allWords = Request.QueryString["AllWords"];
            // Perform search
            list.DataSource = CatalogAccess.SearchEmpresas(searchString, allWords, pageEmp, out howManyPages);
            list.DataBind();
            if (list.Items.Count == 0)
            {
                quantidadeLabel.Visible = true;
                quantidadeLabel.Text = "Nenhuma ocorrência encontrada.<br />";
            }
            // Display pager
            firstPageUrl = Link.ToSearch(searchString, allWords.ToUpper() == "TRUE", "1", "1");
            pagerFormat = Link.ToSearch(searchString, allWords.ToUpper() == "TRUE", page, "{1}");
        }
        
        
        // Display pager controls
        topPager.Show(int.Parse(pageEmp), howManyPages, firstPageUrl, pagerFormat, false);
        bottomPager.Show(int.Parse(pageEmp), howManyPages, firstPageUrl, pagerFormat, true);
    }
}